import namespace from "../namespace";
import extend from "lodash/extend";

class Circle extends namespace.shape.Oval {
  NAME = `${namespace.namespace}.shape.Circle`;
  constructor(attr, setter, getter) {
    super();

    this.isCircle = true;

    this.setterWhitelist = extend(
      {
        diameter(d) {
          return this.setDiameter(d);
        },
        radius(r) {
          return this.setRadius(r);
        }
      },
      this.setterWhitelist,
      setter
    );

    delete this.getterWhitelist.width;
    delete this.getterWhitelist.height;

    this.getterWhitelist = extend(
      {
        diameter() {
          return this.getDiameter();
        },
        radius() {
          return this.getRadius();
        }
      },
      this.getterWhitelist,
      getter
    );

    this.setKeepAspectRatio(true);

    super.attr(attr);
  }

  setDiameter(d) {
    let center = this.getCenter();
    this.setDimension(d, d);
    this.setCenter(center);

    return this;
  }

  getDiameter() {
    return this.getWidth();
  }

  setRadius(r) {
    this.setDiameter(r * 2);
    return this;
  }

  getPersistentAttrs() {
    let attrs = super.getPersistentAttrs();
    // 圆形无角度
    delete attrs.radius;
    return attrs;
  }
}

namespace.shape.Circle = Circle;
